package com.base.cn.platform.os.controller.user.integral;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.common.utils.action.ActionKey;
import com.base.cn.platform.os.entity.user.integral.CusUserIntegralRecord;
import com.base.cn.platform.os.service.manage.user.integral.CusUserIntegralRecordService;
import com.base.cn.platform.os.service.manage.user.integral.CusUserIntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 后台积分
 *
 * @author ll
 * @create 2018-04-27
 */
@Controller
@RequestMapping("/admin/user/cus")
public class AdminCusUserIntegralController extends AdminBaseController {

    @Autowired
    private CusUserIntegralService cusUserIntegralService;
    @Autowired
    private CusUserIntegralRecordService cusUserIntegralRecordService;

    /**
     * 赠送积分
     * @param userId
     * @param score
     * @return
     */
    @RequestMapping("/addUserIntegral")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.USER,action = "赠送学员积分")
    public Map<String,Object> addUserIntegral(@RequestParam("userId")BigDecimal userId,
                                              @RequestParam("score")Long score){
        return cusUserIntegralService.addUserIntegral(ActionKey.GIFT,userId,null,score.intValue(),2);
    }

    /**
     * 搜索用户奖励积分
     * @param model
     * @param currentPage
     * @param pamars
     * @return
     */
    @RequestMapping("/ajax/queryIntegralRecord")
    public String  queryIntegralRecord(Model model,
                                       @RequestParam(value = "currentPage",required = false,defaultValue = "1")int currentPage,
                                       @RequestBody CusUserIntegralRecord pamars ){
        Map<String,Object> dataMap =cusUserIntegralRecordService.queryCusUserIntegralRecordListPage(currentPage,pamars,true);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/user/integral/integral_record_ajax_list");
    }


    /**
     * to 积分流水列表页面
     * @return
     */
    @RequestMapping("/toIntegralRecord")
    public String toIntegralRecord(Model model,@RequestParam(value = "recordType",required = false)Integer recordType) {
        model.addAttribute("recordType", recordType);
        return resultPage("/user/integral/integral_record_list");
    }
}
